extends Camera2D

onready var sms=$"sms"
var bags=false

func _process(_delta):
	if(sys.cur_sce==sys.scene.gaming):
		position.x+=(sys.smcr.position.x-position.x)/32
		position.y+=(sys.smcr.position.y-position.y)/16
	if(sys.cur_sce==sys.scene.gaming&&i.keys.bag):
		if(sys.smcr.if_bag):
			if(!bags):
				if(sms.is_connected("tween_all_completed",self,"tac")):
					sms.disconnect("tween_all_completed",self,"tac")
				for t0 in $"Control/bag_scroll/v".get_children():
					$"Control/bag_scroll/v".remove_child(t0)
				for t0 in sys.smcr.items:
					var its=preload("res://scenes/frags/item_s.tscn").instance()
					its.loadi(t0[0],t0[1])
					$"Control/bag_scroll/v".add_child(its)
				sms.remove_all()
				$"Control/bag_scroll".show()
				sms.interpolate_property($"Control/bag_scroll","rect_position",Vector2(0,0),Vector2(768,128),1,Tween.TRANS_CUBIC,Tween.EASE_OUT)
				sms.interpolate_property($"Control/bag_scroll","rect_size",Vector2(0,0),Vector2(256,512),1,Tween.TRANS_CUBIC,Tween.EASE_OUT)
				sms.start()
			else:
				sms.remove_all()
				sms.interpolate_property($"Control/bag_scroll","rect_position",Vector2(768,128),Vector2(0,0),1,Tween.TRANS_CUBIC,Tween.EASE_OUT)
				sms.interpolate_property($"Control/bag_scroll","rect_size",Vector2(256,512),Vector2(0,0),1,Tween.TRANS_CUBIC,Tween.EASE_OUT)
				sms.start()
				if(!sms.is_connected("tween_all_completed",self,"tac")):
					sms.connect("tween_all_completed",self,"tac")
			bags=!bags

func tac():
	$"Control/bag_scroll".hide()

func close_bag():
	bags=false
	sms.remove_all()
	sms.interpolate_property($"Control/bag_scroll","rect_position",Vector2(768,128),Vector2(0,0),1,Tween.TRANS_CUBIC,Tween.EASE_OUT)
	sms.interpolate_property($"Control/bag_scroll","rect_size",Vector2(256,512),Vector2(0,0),1,Tween.TRANS_CUBIC,Tween.EASE_OUT)
	sms.start()
	if(!sms.is_connected("tween_all_completed",self,"tac")):
		sms.connect("tween_all_completed",self,"tac")

func item_clicked(id):
	print(id)

func y():
	sys.if_user_agrees=true
	sys.emit_signal("user_has_made_their_decision")

func n():
	sys.if_user_agrees=false
	sys.emit_signal("user_has_made_their_decision")
